package org.nfIt.controller;

import com.github.pagehelper.PageInfo;
import org.nfIt.dto.product.CategoryBrandDto;
import org.nfIt.entity.product.Brand;
import org.nfIt.entity.product.CategoryBrand;
import org.nfIt.service.CategoryBrandService;
import org.nfIt.vo.common.Result;
import org.nfIt.vo.common.ResultCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClossName:CategoryBrandController
 * Pakage:org.nfIt.controller
 * Description
 *
 * @Author L
 * @Create 2024/8/16 20:27
 * @Version 2023.1.3
 */
@RestController
@RequestMapping(value = "/admin/product/categoryBrand")
public class CategoryBrandController {

    @Autowired
    private CategoryBrandService categoryBrandService ;

    /**
     * 分类品牌条件查询
     * @param page 当前页
     * @param limit 每页记录数
     * @param CategoryBrandDto 查询条件
     */
    @GetMapping("/{page}/{limit}")
    public Result<PageInfo<CategoryBrand>> findByPage(@PathVariable Integer page, @PathVariable Integer limit, CategoryBrandDto CategoryBrandDto) {
        PageInfo<CategoryBrand> pageInfo = categoryBrandService.findByPage(page, limit, CategoryBrandDto);
        return Result.build(pageInfo , ResultCodeEnum.SUCCESS) ;
    }

    /**
     * 添加品牌
     */
    @PostMapping("/save")
    public Result save(@RequestBody CategoryBrand categoryBrand) {
        categoryBrandService.save(categoryBrand);
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }


//    根据分类id查询对应的品牌数据
    @GetMapping("/findBrandByCategoryId/{categoryId}")
    public Result findBrandByCategoryId(@PathVariable Long categoryId) {
        List<Brand> list = categoryBrandService.findBrandByCategoryId(categoryId);
        return Result.build(list, ResultCodeEnum.SUCCESS) ;
    }


    //TODO 修改和删除


}
